extends PanelContainer
#主场景,处理界面,controller和model的交互

var _controller : Controller

@onready var 结果显示标签参数: Label = $纵向布局器/显示结果容器/结果显示标签

# Called when the node enters the scene tree for the first time.
func _ready() -> void:

	var model: Model = Model.new()
	var controller: Controller = Controller.new(model)
	_controller = controller
	controller.结果变化信号.connect(_on_display_changed)
	绑定所有按钮信号(self)
	
func 绑定所有按钮信号(node):
	# 如果节点是Button类型.当按钮被点击时,发出点击信号,将按钮的text,作为参数,
	if node is Button:
		node.pressed.connect(self._on_button_pressed.bind(node.text))
	# 遍历该节点的子节点
	for child in node.get_children():
		绑定所有按钮信号(child)

## 按钮按下信号绑定
func _on_button_pressed(text: String) -> void:
	_controller.input_value(text)

func _on_display_changed(text: String) -> void:
	结果显示标签参数.text = text
